package com.demo.job;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ServiceLunaJob {

    /**
     * 1、简单任务示例（Bean模式）
     */
    @XxlJob("serviceLunaJobHandler")
    public void serviceLunaJobHandler() {
        String param = XxlJobHelper.getJobParam();
        XxlJobHelper.log("param:{}", param);
        log.info("param:{}", param);
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();
        int key = shardIndex % shardTotal;

        JSONObject jsonObject = JSON.parseObject(param);
        Object value = jsonObject.get(key);
        XxlJobHelper.log("value:{}", value);
        log.info("value:{}", value);
        XxlJobHelper.handleSuccess();
    }
}
